﻿<UserControl x:Class="DiscogsNet.ReleaseViewerExample.ReleaseViewer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:DiscogsNet.ReleaseViewerExample"
             mc:Ignorable="d" 
             d:DesignHeight="500" d:DesignWidth="600"
             Background="White">
    <UserControl.Resources>
        <Style x:Key="SectionHeader" TargetType="{x:Type TextBlock}">
            <Setter Property="Margin" Value="8 4 4 4" />
        </Style>

        <Style x:Key="SectionBorder" TargetType="{x:Type Border}">
            <Setter Property="Background" Value="LightGray" />
            <Setter Property="BorderBrush" Value="Black" />
            <Setter Property="BorderThickness" Value="0 0 0 1" />
            <Setter Property="SnapsToDevicePixels" Value="True" />
        </Style>

        <DataTemplate x:Key="TracklistWithArtists">
            <ItemsControl ItemsSource="{Binding Path=Tracklist}" Margin="8 4 4 4">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="50" Width="Auto" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition MinWidth="50" Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <TextBlock Grid.Column="0" Text="{Binding Position}" Margin="0 0 2 0" />
                            <TextBlock Grid.Column="1" Text="{Binding Aggregate.JoinedArtistsFixed}" Margin="0 0 2 0" />
                            <TextBlock Grid.Column="2" Text="{Binding Title}" HorizontalAlignment="Left" Margin="0 0 2 0" />
                            <TextBlock Grid.Column="3" Text="{Binding Duration}" Margin="0 0 2 0" />
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </DataTemplate>

        <DataTemplate x:Key="TracklistWithoutArtists">
            <ItemsControl ItemsSource="{Binding Path=Tracklist}" Margin="8 4 4 4">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="50" Width="Auto" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition MinWidth="50" Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <TextBlock Grid.Column="0" Text="{Binding Position}" />
                            <TextBlock Grid.Column="1" Text="{Binding Title}" HorizontalAlignment="Left" />
                            <TextBlock Grid.Column="2" Text="{Binding Duration}" />
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </DataTemplate>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <local:ReleaseHeaderViewer Grid.Row="0" />

        <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
            <StackPanel>
                <Border Style="{StaticResource SectionBorder}">
                    <TextBlock Style="{StaticResource SectionHeader}" Text="Tracklist" />
                </Border>

                <ContentControl Name="TracklistContentControl" Content="{Binding}">
                    <ContentControl.Style>
                        <Style>
                            <Setter Property="ContentControl.ContentTemplate" Value="{StaticResource TracklistWithoutArtists}" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Aggregate.HasTrackArtists}" Value="True">
                                    <Setter Property="ContentControl.ContentTemplate" Value="{StaticResource TracklistWithArtists}" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ContentControl.Style>
                </ContentControl>

                <ContentControl>
                    <ContentControl.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Aggregate.HasExtraArtists}" Value="False">
                                    <Setter Property="ContentControl.Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ContentControl.Style>

                    <StackPanel>
                        <Border Style="{StaticResource SectionBorder}">
                            <TextBlock Style="{StaticResource SectionHeader}" Text="Credits:" />
                        </Border>
                    </StackPanel>
                </ContentControl>

                <ItemsControl ItemsSource="{Binding Path=ExtraArtists}" Margin="8 4 4 4">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Role}" />
                                <TextBlock Text=" - " />
                                <TextBlock Text="{Binding Aggregate.NameVariationFixed}" />
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

                <ContentControl>
                    <ContentControl.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Aggregate.HasNotes}" Value="False">
                                    <Setter Property="ContentControl.Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ContentControl.Style>

                    <StackPanel>
                        <Border Style="{StaticResource SectionBorder}">
                            <TextBlock Style="{StaticResource SectionHeader}" Text="Notes:" />
                        </Border>

                        <TextBlock Text="{Binding Notes}" Margin="8 4 4 4" />
                    </StackPanel>
                </ContentControl>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</UserControl>
